"""
统计同一字符串出现的次数
随机生成有重复内容的字符串，使用字符串的count方法进行统计
"""
import random
import string

result = {}
# 随机生成一个字符串
# 获取相关长度随机数
n1 = random.randint(1, len(string.digits))
n2 = random.randint(1, len(string.ascii_letters))
n3 = random.randint(1, len(string.punctuation))
print(n1, n2, n3)

# 获取随机长度的指定字符
con1 = random.sample(string.digits, n1)
con2 = random.sample(string.ascii_letters, n2)
con3 = random.sample(string.punctuation, n3)
print(con1, con2, con3)

# 进行相关内容的合并
r1 = ''.join(con1)
r2 = ''.join(con2)
r3 = ''.join(con3)
strCon = r1 + r2 + r3
####################################
# 添加重复字符
listr = list(strCon)
number = len(listr)
for i in range(number):
    n = random.randint(1, number)
    m = random.randint(0, number)
    tmp = listr[m]
    listr.insert(n, tmp)
strCon = ''.join(listr)
#######################################
# 获取字符串中的每个字符
for i in strCon:
    result[i] = strCon.count(i)

print(result)
